﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// 总体参数分析导航条
	/// </summary>
	public partial class SAROverallAnalyseNavBar : UserControl
	{
        private Grid[] lines;
        private StackPanel[] radios;
        private TextBlock[] titles;

		public SAROverallAnalyseNavBar()
		{
			this.InitializeComponent();
            lines = new Grid[4];
            lines[0] = line1;
            lines[1] = line2;
            lines[2] = line3;
            lines[3] = line4;

            radios = new StackPanel[4];
            radios[0] = stackPanelGroup1;
            radios[1] = stackPanelGroup2;
            radios[2] = stackPanelGroup3;
            radios[3] = stackPanelGroup4;

            titles = new TextBlock[5];
            titles[0] = txtTitle1;
            titles[1] = txtTitle2;
            titles[2] = txtTitle3;
            titles[3] = txtTitle4;
            titles[4] = txtTitle5;
		}

        /// <summary>
        /// 大步骤修改的事件
        /// </summary>
        public event StepIndexChangedHandler SARStepIndexChanged;

        /// <summary>
        /// 单选框
        /// </summary>
        public event RadioIndexChangedHandler SARRadioIndexChanged;

        private int currentStepIndex = 0;
        public int SARCurrentStepIndex
        {
            get { return currentStepIndex; }
            set 
            {
                //先把所有内容隐藏
                for (int i = 0; i < 4; i++)
                {
                    lines[i].Visibility = System.Windows.Visibility.Hidden;
                    radios[i].Visibility = System.Windows.Visibility.Hidden;                
                }
                pathLastSelected.Visibility = System.Windows.Visibility.Hidden;
                titles[currentStepIndex].Foreground = new SolidColorBrush(Color.FromRgb(0x3a, 0x47, 0x4c));
                
                currentStepIndex = value;

                //再显示该显示的内容
                if (value < 4)
                {
                    lines[currentStepIndex].Visibility = System.Windows.Visibility.Visible;
                    radios[currentStepIndex].Visibility = System.Windows.Visibility.Visible;
                    imgRadioBack.Visibility = Visibility.Visible;
                }
                else
                {
                    pathLastSelected.Visibility = System.Windows.Visibility.Visible;
                    imgRadioBack.Visibility = Visibility.Hidden;
                }

                titles[currentStepIndex].Foreground = new SolidColorBrush(Color.FromRgb(0x71, 0x8b, 0x15));

                gridCurrentIcon.Margin = new Thickness(56.75 + 160 * value, 21, 0, 0);
            }
        }

        private void Step1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (currentStepIndex == 0)
            {
                return;
            }
            SARCurrentStepIndex = 0;
            if (SARStepIndexChanged != null)
            {
                SARStepIndexChanged.Invoke(0);
            }
        }

        private void Step2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (currentStepIndex == 1)
            {
                return;
            }
            SARCurrentStepIndex = 1;
            if (SARStepIndexChanged != null)
            {
                SARStepIndexChanged.Invoke(1);
            }
        }

        private void Step3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (currentStepIndex == 2)
            {
                return;
            }
            SARCurrentStepIndex = 2;
            if (SARStepIndexChanged != null)
            {
                SARStepIndexChanged.Invoke(2);
            }
        }

        private void Step4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (currentStepIndex == 3)
            {
                return;
            }
            SARCurrentStepIndex = 3;
            if (SARStepIndexChanged != null)
            {
                SARStepIndexChanged.Invoke(3);
            }
        }

        private void Step5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (currentStepIndex == 4)
            {
                return;
            }
            SARCurrentStepIndex = 4;
            if (SARStepIndexChanged != null)
            {
                SARStepIndexChanged.Invoke(4);
            }
        }

        private void rdo1_1_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(0, 0);
            }
        }

        private void rdo1_2_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(0, 1);
            }
        }

        private void rdo1_3_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(0, 2);
            }
        }

        private void rdo2_1_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(1, 0);
            }
        }

        private void rdo2_2_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(1, 1);
            }
        }

        private void rdo3_1_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(2, 0);
            }
        }

        private void rdo3_2_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(2, 1);
            }
        }

        private void rdo3_3_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(2, 2);
            }
        }

        private void rdo4_1_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(3, 0);
            }
        }

        private void rdo4_2_SAR_RadioBtnChecked(object sender, MouseButtonEventArgs e)
        {
            if (SARRadioIndexChanged != null)
            {
                SARRadioIndexChanged.Invoke(3, 1);
            }
        }
	}

    public delegate void StepIndexChangedHandler(int stepIndex);
    public delegate void RadioIndexChangedHandler(int stepIndex,int radioIndex);
}